package com.yc.cloud.filter;

import com.yc.cloud.utils.MinIoUtil;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import java.io.IOException;

/**
 * @author 杨智杰
 * @since 2021/8/26 14:28
 */
@Component
public class LinkCheckFilter implements Filter {

    /**
     * 未连接到minio服务器跳转路径
     */
    private final String NOT_LINK = "/notLink";

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
            throws ServletException, IOException {
        if (MinIoUtil.MINIO_IS_LINK) {
            filterChain.doFilter(servletRequest, servletResponse);
        } else {
            servletRequest.getRequestDispatcher(NOT_LINK).forward(servletRequest, servletResponse);
        }
    }
}
